package com.h2cloud.annotation;

/**
 * @Package: com.h2cloud.annotation
 * @ClassName: AnnotationTest
 * @Author: h2cloud
 * @CreateTime: 2022/6/14 2:58 下午
 * @Description:
 */

import java.lang.reflect.Field;
import java.lang.reflect.Method;


public class AnnotationTest {
	public static void main(String[] args) throws Exception {
		// 获取类上的注解
		Class<Demo> clazz = Demo.class;
		MyAnnotation annotationOnClass = clazz.getAnnotation(MyAnnotation.class);
		System.out.println(annotationOnClass.getValue());

		// 获取成员变量上的注解
		Field name = clazz.getField("name");
		MyAnnotation annotationOnField = name.getAnnotation(MyAnnotation.class);
		System.out.println(annotationOnField.getValue());

		// 获取 hello方法上的注解
		Method hello = clazz.getMethod("hello", (Class<?>[]) null);
		MyAnnotation annotationOnMethod = hello.getAnnotation(MyAnnotation.class);
		System.out.println(annotationOnMethod.getValue());

		// 获取 defaultMethod方法上的注解
		Method defaultMethod = clazz.getMethod("defaultMethod", (Class<?>[]) null);
		MyAnnotation annotationOnDefaultMethod = defaultMethod.getAnnotation(MyAnnotation.class);
		System.out.println(annotationOnDefaultMethod.getValue());

	}
}
